<template>
    <div id="home" class="log">
        <div class="harnessNav">
            <div>
                <div>
                    日志信息
                </div>
                <div class="userNavT">
                    <!--<div :class="{navSel:isNavSel = tempName.name == 0 ? true : false }">
                        事件中心
                    </div>-->
                </div>
            </div>
        </div>
        <div class="harnDetaS">
            <div class="nav">
                <h1>信息选项</h1>
                <div>
                    <div class="seek">
                        <div class="nameSele">
                            <select @change="nameTypeChange" v-model="NameLogType">
                              <option v-for="(type,index) in NameLogTypes">{{type}}</option>
                            </select>
                        </div>
                        <div></div>
                        <div></div>
                        <div></div>
                    </div>
                </div>
            </div>
            <div class="harnDeta" v-loading="loading" element-loading-text="拼命加载中">
                <ul>
                    <li class="firstLi">
                        <div>账户</div>
                        <div>服务名</div>
                        <div>操作</div>
                        <div>备注</div>
                        <div>结果</div>
                    </li>
                    <li class="dataLi" v-for="(item,index) in items" v-show="isDatas">
                        <div>{{item.account | StrFun}}</div>
                        <div>{{item.createTime | ctimeFun}}</div>
                        <div>{{item.doWhat | StrFun}}</div>
                        <div>{{item.remark | StrFun}}</div>
                        <div>{{item.result | AAAStrFun}}</div>
                    </li>
                    <li class="nullLi" v-show="!isDatas">
                        <div>暂时没有数据</div>
                    </li>
                    <li class="lastLi">
                        <div class="lastSel">
                            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 30, 40]" :page-size="pageSizeNum"
                                :current-page="currentPage" layout="total, sizes, prev, pager, next" :total="totalNum">
                                </el-pagination>
                        </div>
                        <div class="lastPag">
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
    import { mapActions, mapState } from 'vuex'
    export default {
        name: 'log',
        data() {
            return {
                isNavSel: true,
                pageSizeNum: 10,
                totalNum: 0,
                currentPage: 1,
                isDatas: false,
                loading: false,
                items: [],
                NameLogType: 'serviceLogServer',
                NameLogTypes: []
            }
        },
        computed: mapState(['']),
        created: function () {
            var self = this
            // 获取用户信息
            self.getNameLogList({
            }).then((data) => {
                self.loading = false
                console.log(JSON.parse(JSON.stringify(data)))
                if (data.code === 200) {
                    if (data.data.length > 0) {
                        self.NameLogTypes = data.data
                    } else {
                        self.NameLogTypes = ['暂无信息']
                    }
                }
            }).catch(msg => {
                console.log(msg)
            })
            // 获取默认日志列表
            self.loading = true
            self.getAllLogList({
                name: self.NameLogType,
                pageNo: self.currentPage,
                pageSize: self.pageSizeNum,
            }).then((data) => {
                self.loading = false
                console.log(JSON.parse(JSON.stringify(data)))
                if (data.code === 200) {
                    if (data.data.list.length > 0) {
                        self.items = data.data.list
                        self.totalNum = data.data.count
                        self.isDatas = true
                    } else {
                        self.isDatas = false
                    }

                }
            }).catch(msg => {
                console.log(msg)
            })
        },
        filters: {
            ctimeFun: function (val) {
                if (val) {
                    var now = new Date(val)
                    var year = now.getYear() - 100;
                    var month = now.getMonth() + 1;
                    month = month > 9 ? month : "0" + month
                    var date = now.getDate();
                    date = date > 9 ? date : "0" + date
                    var hour = now.getHours();
                    hour = hour > 9 ? hour : "0" + hour
                    var minute = now.getMinutes();
                    minute = minute > 9 ? minute : "0" + minute
                    return "20" + year + "-" + month + "-" + date + "   " + hour + ":" + minute;
                } else {
                    return '无';
                }

            },
            AAAStrFun: function (val) {
                if (val == false) {
                    return '失败'
                } else {
                    return '成功'
                }
            },
            StrFun: function (val) {
                if (val) {
                    return val
                } else {
                    return '无'
                }
            }
        },
        methods: {
            // 设置每页个数
            handleSizeChange(val) {
                var self = this
                self.loading = true
                self.getAllLogList({
                    name: self.NameLogType,
                    pageNo: self.pageSizeNum,
                    pageSize: self.currentPage
                }).then((data) => {
                    self.loading = false
                    console.log(JSON.parse(JSON.stringify(data)))
                    if (data.code === 200) {
                        if (data.data.list.length > 0) {
                            self.items = data.data.list
                            self.totalNum = data.data.count
                            self.isDatas = true
                        } else {
                            self.isDatas = false
                        }

                    }
                }).catch(msg => {
                    console.log(msg)
                })
            },
            // 点击分页
            handleCurrentChange(val) {
                console.log(this.NameLogType)
                var self = this
                self.loading = true
                self.currentPage = val
                self.getAllLogList({
                    name: self.NameLogType,
                    pageNo: val,
                    pageSize: self.pageSizeNum
                }).then((data) => {
                    self.loading = false
                    console.log(JSON.parse(JSON.stringify(data)))
                    if (data.code === 200) {
                        if (data.data.list.length > 0) {
                            self.items = data.data.list
                            self.totalNum = data.data.count
                            self.isDatas = true
                        } else {
                            self.isDatas = false
                        }

                    }
                }).catch(msg => {
                    console.log(msg)

                })
            },
            // 选择任务名称
            nameTypeChange() {
                console.log(this.NameLogType)
                var self = this
                self.loading = true
                self.getAllLogList({
                    name: self.NameLogType,
                    pageNo: self.currentPage,
                    pageSize: self.pageSizeNum,
                }).then((data) => {
                    self.loading = false
                    console.log(JSON.parse(JSON.stringify(data)))
                    if (data.code === 200) {
                        if (data.data.list.length > 0) {
                            self.items = data.data.list
                            self.totalNum = data.data.count
                            self.isDatas = true
                        } else {
                            self.isDatas = false
                        }

                    }
                }).catch(msg => {
                    console.log(msg)
                })
            },
             ...mapActions(['getAllLogList','getNameLogList'])
        }
    }

</script>

<style scoped>
    .harnessNav {
        width: 100%;
        height: 75px;
    }
    
    .harnessNav>div {
        margin: 0 auto;
        width: 96%;
        height: 75px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .harnessNav>div>div:nth-child(1) {
        width: 140px;
        height: 41px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 19px;
        color: #fff;
        background: url('/static/img/zhi.png') no-repeat;
        background-size: 100%;
    }
    
    .userNavT {
        display: flex;
        align-items: center;
    }
    
    .userNavT>div {
        font-size: 18px;
        color: #7dbcf3;
        cursor: pointer;
        width: 85px;
        position: relative;
        text-align: center;
    }
    
    .navSel:before {
        content: '';
        position: absolute;
        bottom: -5px;
        right: 0;
        width: 85px;
        height: 4px;
        background-color: #2cc8b5;
        border-bottom-left-radius: 3px;
        border-bottom-right-radius: 3px;
        border-top-left-radius: 3px;
        border-top-right-radius: 3px;
    }
    
    .harnDetaS {
        margin: 0 auto;
        width: 95%;
    }
    
    .nav {
        height: 150px;
        width: 100%;
        background-color: #fff;
        overflow: hidden;
    }
    
    .nav>h1 {
        width: 100%;
        font-size: 18px;
        line-height: 40px;
        color: #34bba0;
        border-bottom: 1px solid #f4f5f6;
        margin: 0;
        padding: 0;
        height: 40px;
        padding-left: 25px;
    }
    
    .seek {
        width: 100%;
        height: 105px;
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        align-items: center;
        overflow: hidden;
    }
    
    .seek>div {
        margin-top: 7px;
        width: 40%;
        height: 35px;
    }
    
    .nameSele>select {
        border: 1px solid #ccc;
        width: 250px;
        padding-left: 15px;
        height: 35px;
        line-height: 35px;
        font-size: 14px;
        border-radius: 3px;
    }
    
    .harnDeta {
        overflow: hidden;
        margin-top: 20px;
        width: 100%;
        min-height: 550px;
        height: 100%;
        border: 1px solid #ccc;
    }
    
    .harnDeta>ul>li {
        display: flex;
        border-bottom: 1px solid #ccc;
        height: 45px;
        line-height: 45px;
        text-align: center;
        overflow: hidden;
    }
    
    .harnDeta>ul>li>div {
        width: 25%;
        border-left: 1px solid #ccc;
        padding-left: 2px;
        padding-right: 2px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    
    .harnDeta>ul>li>div:nth-child(1) {
        border-left: 0;
        width: 20%;
    }
    
    .harnDeta>ul>li>div:nth-child(2) {
        width: 15%;
    }
    
    .harnDeta>ul>li>div:nth-child(3) {
        width: 15%;
    }
    
    .harnDeta>ul>li>div:nth-child(4) {
        width: 35%;
    }
    
    .harnDeta>ul>li>div:nth-child(5) {
        width: 15%;
    }
    
    .harnDeta>ul .dataLi:hover {
        background-color: #E5E9F2;
    }
    
    .harnDeta>ul .firstLi {
        background-color: #e5e9f2;
    }
    
    .harnDeta>ul .nullLi>div:nth-child(1) {
        width: 100%;
        text-align: center;
    }
    
    .harnDeta>ul .dataLi>div:last-child small span {
        font-size: 12px;
        margin-right: 3px;
        color: #fff
    }
    
    .elbut {
        color: #666;
        margin: 0;
        padding: 0;
    }
    
    .harnDeta>ul .lastLi {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    .harnDeta>ul .lastLi>div:nth-child(1) {
        border-left: 0;
        margin-top: 15px;
        height: 45px;
        z-index: 1;
        width: 80%;
    }
    
    .harnDeta>ul .lastLi>div:nth-child(2) {
        border-left: 0;
        margin-top: 15px;
        height: 45px;
        width: 10%;
    }
</style>